

export function stringToResult(list){
    let arr = []
    list.forEach(e => {

        let a = e.result.split(':')

        let data = {
            id : e.id,
            topicId : e.topicId,
            params : [],
            result : {
                dataType : a[0],
                data : a[1]
            }
        }

        let li = e.params.split(';')

        li.pop()

        li.forEach(n => {
            let c = n.split(':')
            data.params.push({
                dataType : c[0],
                data : c[1]
            })
        })

        arr.push(data)
    });

    return arr
}

export function resultToString(arr){
    let list = []

    for (let index = 0; index < arr.length; index++) {
        const element = arr[index];
        let data = {
            id : element.id,
            params : '',
            result : '',
        }

        for (let i = 0; i < element.params.length; i++) {
            const e = element.params[i];
            if (!e.dataType || !e.data) {
                return '请将参数类型和数据补全'
            }
            data.params += updateData(e.dataType) + ':' + updateData(e.data) + ';'
        }

        if (!element.result.dataType || !element.result.data) {
            return '请将参数类型和数据补全'
        }

        data.result += updateData(element.result.dataType) + ':' + updateData(element.result.data)

        list.push(data)
    }

    return list
}

function updateData(data){
    return data
}

export default {
    stringToResult,
    resultToString
}